package org.jeecg.modules.mobile.upload;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.sanitation2.entity.LwgyScoreSanitation;
import org.jeecg.modules.sanitation2.entity.LwgyTargetType;
import org.jeecg.modules.sanitation2.service.ILwgyScoreSanitationService;
import org.jeecg.modules.sanitation2.service.ILwgyTargetTypeService;
import org.jeecg.modules.sanitation2.vo.LwgyScoreSanitationPage;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @Description: 离线数据
* @Author: jeecg-boot
* @Date:   2021-04-29
* @Version: V1.0
*/
/*@Api(tags="离线数据")
@RestController
// @Controller("testcontroller")
@RequestMapping("/sanitation2/lwgyScoreSanitation")
@Slf4j
public class LwgyUploadDownloadController {
   @Autowired
   private ILwgyScoreSanitationService lwgyScoreSanitationService;
   @Autowired
   private ILwgyTargetTypeService lwgyTargetTypeService;

    *//**
     * 上传离线打分数据
     *
     *//*
    @AutoLog(value = "上传离线打分数据")
    @ApiOperation(value="上传离线打分数据", notes="上传离线打分数据")
    @PostMapping("/uploadOfflineData")
    public Result<?>uploadOfflineData(@RequestBody List<LwgyScoreSanitationPage> lwgyScoreSanitationPages){
       LwgyScoreSanitationPage lwgyScoreSanitationPage = new LwgyScoreSanitationPage();//
       lwgyScoreSanitationPage.setId("123");
       lwgyScoreSanitationPage.setBuildingId("123");
       List<LwgyTargetType> lwgyTargetTypes = new ArrayList<>(2);
       LwgyTargetType lwgyTargetType = new LwgyTargetType();
       lwgyTargetType.setSanitationId(lwgyScoreSanitationPage.getId());
       lwgyTargetType.setId("1231");
       lwgyTargetTypes.add(lwgyTargetType);							//构建打分指标
       lwgyScoreSanitationPage.setLwgyTargetTypeList(lwgyTargetTypes);
        lwgyScoreSanitationPages.add(lwgyScoreSanitationPage);			//构建打分VO
        List<LwgyTargetType> lwgyTargetTypeLists = new ArrayList<>(20);
        LwgyScoreSanitation lwgyScoreSanitation = null;
        List<LwgyScoreSanitation> lwgyScoreSanitations = new ArrayList<>(15);
        for (LwgyScoreSanitationPage scoreSanitationPage : lwgyScoreSanitationPages) {
            List<LwgyTargetType> lwgyTargetTypeList = scoreSanitationPage.getLwgyTargetTypeList();//提取打分指标
            lwgyTargetTypeLists.addAll(lwgyTargetTypeList);						//放入单独集合类
            lwgyScoreSanitation = new LwgyScoreSanitation();
            BeanUtils.copyProperties(scoreSanitationPage, lwgyScoreSanitation);//逐个取出打分列表内容放入打分实体类
            lwgyScoreSanitations.add(lwgyScoreSanitation);						//构建新的打分实体类集合
        }
        lwgyScoreSanitationPages.forEach(System.out::println);
        System.out.println("============================");
        lwgyTargetTypeLists.forEach(System.out::println);
        lwgyScoreSanitationService.saveBatch(lwgyScoreSanitations);//批量保存打分集合
        lwgyTargetTypeService.saveBatch(lwgyTargetTypeLists); 		//批量保存打分指标各项成绩
        return Result.OK();
    }


    *//**
     * 上传离线打分单元测试
     *//*
    @Test
    public void test(){
        List<LwgyScoreSanitationPage> lwgyScoreSanitationPages = new ArrayList<>(2);
        LwgyScoreSanitationPage lwgyScoreSanitationPage = new LwgyScoreSanitationPage();
        lwgyScoreSanitationPage.setId("000");
        lwgyScoreSanitationPage.setBuildingId("000");
        List<LwgyTargetType> lwgyTargetTypes = new ArrayList<>(2);
        LwgyTargetType lwgyTargetType = new LwgyTargetType();
        lwgyTargetType.setSanitationId(lwgyScoreSanitationPage.getId());
        lwgyTargetType.setId("0000");
        lwgyTargetTypes.add(lwgyTargetType);
        lwgyScoreSanitationPage.setLwgyTargetTypeList(lwgyTargetTypes);
        lwgyScoreSanitationPages.add(lwgyScoreSanitationPage);
        uploadOfflineData(lwgyScoreSanitationPages);
    }
}*/
